package cn.tedu.javagame.FirePlane;

import javax.swing.*;
import java.awt.*;

public class enemyBullet {
    int x, y;
    static Image bulletImg;
    Enemy shooter; // 记录发射该子弹的敌机

    //静态代码块，当类加载时（进入虚拟机）的时候会执行一次，无论以后创造多少个对象都不再执行
    static {
        bulletImg = new ImageIcon("plane/enemybullet.png").getImage();
    }

    public enemyBullet(int x, int y, Enemy shooter) {
        this.x = x;
        this.y = y;
        this.shooter = shooter;
    }

    public void move() {
        this.y += 5; // 敌机子弹向下移动
    }

    public boolean hitHero(Hero h) {
        Rectangle heroRect = new Rectangle(h.x, h.y, h.heroImg.getWidth(null), h.heroImg.getHeight(null));
        Rectangle bulletRect = new Rectangle(x, y, bulletImg.getWidth(null), bulletImg.getHeight(null));
        return heroRect.intersects(bulletRect);
    }
}